package Pieces;

import logic.BeamDirection;
import logic.Piece;
import logic.Team;

public class Djed implements Piece{
	private Team owner;
	private short direction;
	
	public Djed(Team owner, short orientation){
		this(owner);
		direction = orientation;
	}
	
	public Djed(Team owner){
		this.owner = owner;
		this.direction = 0;
	}

	@Override
	public Team getTeam() {
		return owner;
	}

	@Override
	public BeamDirection reflexBeam(BeamDirection incidence) {
		System.out.println(incidence+" "+direction);
		if(direction%2==1){
			switch (incidence) {
			case UP:
				return BeamDirection.LEFT;
			case LEFT:
				return BeamDirection.UP;
			case DOWN:
				return BeamDirection.RIGHT;
			case RIGHT:
				return BeamDirection.DOWN;
			}
		}else{
			switch (incidence) {
			case UP:
				return BeamDirection.RIGHT;
			case RIGHT:
				return BeamDirection.UP;
			case DOWN:
				return BeamDirection.LEFT;
			case LEFT:
				return BeamDirection.DOWN;
			}
		}
		return BeamDirection.NODIRECTION;
	}

	@Override
	public void resetPiece() {
		direction = 0;
	}

	@Override
	public void rotateLeft() {
		direction = (byte) ((direction+1)%2);
	}

	@Override
	public void rotateRigth() {
		rotateLeft();
	}
	
	public short getOrientation(){
		return direction;
	}

}
